package com.engineering.elink.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.engineering.elink.co.CoinCo;
import com.engineering.elink.common.ResultType;
import com.engineering.elink.service.CoinService;
import com.engineering.elink.util.MapConvert;

@RestController
@RequestMapping("/api/coin")
@Api(value = "积分接口")
public class CoinController {
	
	@Autowired
	private CoinService coinService;
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/getCoinList", method = RequestMethod.GET)
	@ApiOperation(value = "获取积分列表", httpMethod = "GET")
	public Map<String, Object> getCoinList(
			@ApiParam(value = "开始时间", required = false) @RequestParam(value = "beginTime", required = false)  @DateTimeFormat(pattern="yyyy-MM-dd") Date beginTime,
			@ApiParam(value = "结束时间", required = false) @RequestParam(value = "endTime", required = false) @DateTimeFormat(pattern="yyyy-MM-dd") Date endTime,
			@ApiParam(value = "页数", required = true) @RequestParam(value = "pageNo", required = true)  Integer pageNo,
			@ApiParam(value = "每页显示数", required = true) @RequestParam(value = "pageSize", required = true) Integer pageSize
			,HttpServletRequest request) {
		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
		if (userInfo != null && userInfo.containsKey("userId")) {
			String userId = (String) userInfo.get("userId");
			CoinCo coinCo = new CoinCo(pageNo,pageSize);
			coinCo.setBeginTime(beginTime);
			coinCo.setEndTime(endTime);
			coinCo.setUserId(userId);
			return MapConvert.getMap(ResultType.SUCCESS, coinService.getCoinList(coinCo));
		}
		return MapConvert.getMap(ResultType.REQUEST_PARAMS_ERROR);
	}
}
